<include file="Common:header" />
<TYimport plugin='datepicker' />
<TYimport plugin='Ueditor,swfUpload' public="true"/>
<div class="table_content" >
    <form action="{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME)}" id="upForm" method="post"  class="ajax_form">
        <table class="edit_table">
            <tr>
                <td class="tablehead">标题</td>
                <td>
                    <input type="text" name="coupon_name" id="title" class="text w150 required" value="{$postInfo['title']}"/><label class="tips"></label>
                </td>
            </tr>         
            
            
            <tr>
                <td class="tablehead">优惠券类型</td>
                <td>
                	<span class="radio">
                        <input type="radio" id="radio1" name="coupon_type" value="1" checked/><label for="radio1">直接优惠</label>
                        <!-- <input type="radio" id="radio2" name="is_top" value="0" <if condition="!is_null($postInfo['is_top']) and ($postInfo['is_top'] eq 0)">checked</if> /><label for="radio2">关闭</label> -->
                    </span>
                </td>
            </tr>
            
            <tr>
                <td class="tablehead">获取优惠券方法</td>
                <td>
                	<span class="radio">
                        <input type="radio" id="radio2" name="get_type" value="1"/><label for="radio2">注册获得</label>
                        <input type="radio" id="radio3" name="get_type" value="0" /><label for="radio3">分享获得</label>
                        <input type="radio" id="radio4" name="get_type" value="0" /><label for="radio4">活动</label>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="tablehead">减免金额</td>
                <td>
                	<input type="text" class="price" name="price" style="width:50px;padding:10px;text-align:center"/>&nbsp;元
                </td>
            </tr>
            <!-- <tr>
            	<td class="tablehead">状态</td>
                <td>
                	<span class="radio">
                        <input type="radio" id="radio7" name="status" value="1" <if condition="is_null($postInfo['status']) or ($postInfo['status'] eq 1)">checked</if> /><label for="radio7">开启</label>
                        <input type="radio" id="radio8" name="status" value="0" <if condition="!is_null($postInfo['status']) and ($postInfo['status'] eq 0)">checked</if> /><label for="radio8">关闭</label>
                    </span>
                </td>
            </tr> -->
            <tr>
            	 <td class="tablehead">时间</td>
            	 <td>
            	 	开始时间：<input type="text" class="text w150" name="start_time" value='' onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>&nbsp;&nbsp;&nbsp;&nbsp;
            	        结束时间：<input type="text" class="text w150"  name="end_time"  value='' onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" /></td>
            </tr>
        </table>
        <div class="tab_box_btn">
            <!-- <input type="hidden" id="id" name="id" value="{$postInfo['id']}"/> -->
            <input type="button" class="save_btn" value="保存"/>
            <input type="button" class="back_btn" value="返回"/>
        </div>
    </form>
</div>
<script type="text/javascript">


$(".save_btn").click(function(){
	if($('input[name=coupon_name]').val() == ''){
		alert('請輸入優惠券名');return;
	}
	if($('input[name=price]').val() == ''){
		alert('請輸入減免金額');return;
	}
	if($('input[name=start_time]').val() == ''){
		alert('請選擇開始時間');return;
	}
	if($('input[name=end_time]').val() == ''){
		alert('請選擇結束時間');return;
	}
	 var formData = new FormData($( "#upForm" )[0]);  
		$.ajax({
			url:"{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/add_coupon')}",
			type: 'POST',    
	        data : formData,    
	        async: false,    
	        cache: false,    
	        contentType: false,    
	        processData: false,    
			dataType: 'json', 
			success:function(data){
				if (data.status == 1){
	    			callBackTips(data.status, data.info,data.url);
	    		}
				else{
	    			callBackTips(data.status, data.info);
	    		}
			}
		});
});
</script>
<include file="Common:footer" />